#!/usr/bin/env bash
# get abs path
SCRITP_PATH=`cd $(dirname ${BASH_SOURCE[0]});pwd`
source $SCRITP_PATH/logger.sh
sections(){
    local file=$1
    LOG_DEBUG $file
    local sectionPattern=$2
    sectionPattern=${sectionPattern:-.*}
    local val=$(awk '/^\['$sectionPattern'\]$/{printf("%s ",substr($1,2,length($1)-2))}' $file)
    echo $val
}

property() {
    local file=$1
    local section=$2
    local property=$3
    local val=$(awk -F= '/^\['$section'\]$/{a=1} /^\[/{if($0!="['$section']") a=0} {if(a==1 && $1=="'$property'") printf("%s ",$2)}' $file)
    echo $val
}